/*
 * DiscoveryPresenter.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.discovery;

import com.yidiandao.business.data.model.IDiscoveryModel;
import com.yidiandao.business.data.response.DiscoveryMainTypeResponse;
import com.yidiandao.business.ui.widget.view.SuperLoadingLayout;

import java.util.List;

/**
 * 发现-Presenter
 * <p>
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/8 15:40
 */
public class DiscoveryPresenter implements DiscoveryContract.Presenter {

    private DiscoveryContract.View mDiscoveryView;

    private IDiscoveryModel mDiscoveryModel;

    public DiscoveryPresenter(DiscoveryContract.View view, IDiscoveryModel discoveryModel) {
        mDiscoveryView = view;
        mDiscoveryModel = discoveryModel;

        mDiscoveryView.setPresenter(this);
    }

    @Override
    public void start() {
        mDiscoveryModel.loadMainTitle(mDiscoveryView.getPagerTag(),
                new IDiscoveryModel.OnAccessNetListener<List<DiscoveryMainTypeResponse.CatTypeEntity>>() {
                    @Override
                    public void onSuccess(List<DiscoveryMainTypeResponse.CatTypeEntity> catTypeBeen) {
                        mDiscoveryView.refreshContent(mDiscoveryView.checkResultObject(catTypeBeen));
                        mDiscoveryView.setTitleList(catTypeBeen);
                    }

                    @Override
                    public void onFailed() {
                        mDiscoveryView.refreshContent(SuperLoadingLayout.STATE_ERROR);
                    }

                    @Override
                    public void onFinal() {

                    }
                });
    }
}
